#!/usr/bin/env python

import pylab #@UnresolvedImport
import numpy as np
import matplotlib.pyplot as plot #@UnresolvedImport

class BarGraph():

    def __init__(self, title='Bar Graph', xAxis='', yAxis=''):
        self.title = title
        self.xAxis = xAxis
        self.yAxis = yAxis

    def buildGraph(self, data):
        groups, dataSet, standards = self.parseData(data)
        self.ind = np.arange(len(dataSet))
        self.width = 0.33      
        plot.subplot(111)
        self.rects1 = plot.bar(self.ind, dataSet, self.width, color='r', yerr=standards, error_kw=dict(elinewidth=5, ecolor='pink'))
        plot.title(self.title)
        plot.ylabel(self.yAxis)
        plot.xlabel(self.xAxis)
        plot.xticks(self.ind+(self.width/2), groups)
        
    def autoLabel(self, rects):
        for rect in rects:
            height = rect.get_height()
            plot.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height), ha='center', va='bottom')
    
    def parseData(self, data):
        if type(data) != type(dict()):
            raise TypeError
        values, groups, margins = [], [], []
        for key in data.keys():
            groups.append(key[:10])
            values.append(data[key])
            margins.append(0)
        return tuple(groups), tuple(values), tuple(margins)
          
    def displayGraph(self):
        self.autoLabel(self.rects1)
        plot.show()

class Histogram():
    
    def __init__(self, title='Histogram', xAxis='', yAxis=''):
        pylab.xlabel(xAxis)
        pylab.ylabel(yAxis)
        pylab.title(title)
    
    def buildGraph(self, data):
        pylab.grid(True)
        pylab.hist(data)
    
    def displayGraph(self):
        pylab.show()

class BoxPlot():
    
    def __init__(self, title='Box Plot', xAxis='', yAxis=''):
        pylab.title(title)
        pylab.xlabel(xAxis)
        pylab.ylabel('Data Set')

    def buildGraph(self, data):
        pylab.boxplot(data, 0, 'rs', 0)
    
    def displayGraph(self):
        pylab.show()

if __name__ == '__main__':
    graph = BoxPlot()
    graph.buildGraph([5,5,6,7,8,9,0,15,6,2,4,5,2,4,5,7,8,9,10])
    graph.displayGraph()